package com.turing.data.scripts.zjtq.filter

import com.turing.common.util.FileUtils
import com.turing.common.util.ObjectUtils
import com.turing.data.engine.TextUtils
import com.turing.data.engine.utils.ScriptsUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO


/**
 * 场景名称：追加提取单
 * 要素名称：户名
 **/

class AccountName_30233_34_filter {

    static List< TaskElementVO.DrawResultVO > doConvert( DependParamsVO dependParams ){

        List<TaskElementVO.DrawResultVO > resultVOs = ScriptsUtils.tryInitResult(dependParams)
        if (resultVOs!=null && resultVOs.size()>0) {

            List<TaskElementVO.DrawResultVO > defaultResultVOs = new ArrayList<>()
            def resultVO = resultVOs.get(0)
            def text = resultVO.text
            def textPathMap = dependParams.textPathMap
            def JSONTextMap = dependParams.JSONTextMap
            def rawPath = textPathMap.get(resultVO.childTaskSn)
            def rawText = FileUtils.loadJson(rawPath)
            def fileTextStr = ""
            fileTextStr = JSONTextMap.get(resultVO.childTaskSn)
            def start = resultVO.start
            def end = resultVO.end
            if( rawText.substring(end,end+1).equals("）") || rawText.substring(end,end+1).equals(")") ){
                TaskElementVO.DrawResultVO ObjectNew = (TaskElementVO.DrawResultVO) ObjectUtils.deepClone(resultVO)
                ObjectNew = TextUtils.correctPositionInfoByOffset(ObjectNew, 0 , 1, fileTextStr, rawText)
                ObjectNew.text = rawText.substring( start , end + 1 )
                ObjectNew.businessValue = rawText.substring( start , end + 1 )
                defaultResultVOs.add(ObjectNew)
                return defaultResultVOs
            }


            defaultResultVOs.add(resultVOs.get(0))
            return defaultResultVOs
        }

        return  resultVOs
    }

}
